<?php

namespace app\model;

use Webman\Exception\BusinessException;

class UsersModel extends BaseModel
{
    /**
     * 与模型关联的表名
     *
     * @var string
     */
    protected $table = 'users';

    /**
     * 隐藏的属性
     *
     * @var array
     */
    protected $hidden = ['password','openid','unionid'];


    /**
     * 检查用户状态
     * @param $userId
     */
    public static function checkUser($userId){
        $user = self::find($userId);
        if($user){
            if($user->status === -1){
                throw new BusinessException('该用户已被禁用，请联系管理员!', 400);
            }

            return $user;
        }else{
            throw new BusinessException('该用户不存在!', 400);
        }
    }
}